//函数封装简化代码
var btn=document.getElementsByTagName("button");
for (var i=0;i<btn.length;i++){
    btn[i].onclick=function(){
        if(this.innerHTML=="+"){
            hhh(1,this);
        }else{
            hhh(-1,this);
        }
        total();
    }
}
total();		

function hhh(number,btn){	
    if(number==1){
        var span=btn.previousElementSibling;
    }else{
        var span=btn.nextElementSibling;
       // console.log(span)
    }
    var newSpanV=parseInt(span.innerHTML)+number;
    console.log(newSpanV)
    if(newSpanV>0){
        span.innerHTML=newSpanV;
        //单价
        var dj=btn.parentNode.previousElementSibling.lastElementChild.innerHTML;
        console.log(dj)
        //小计
        btn.parentNode.nextElementSibling.lastElementChild.innerHTML=dj*newSpanV;
        //console.log(btn.parentNode.nextElementSibling.lastElementChild.innerHTML)
    }
    
}


function total(){
    var zjf=document.getElementsByTagName("tfoot")[0];
    var zj=zjf.firstElementChild.lastElementChild.lastElementChild;
    var sj=zjf.previousElementSibling.children;
    for (var i=2,sum=0;i<sj.length;i+=2) {
        var sjv=sj[i].lastElementChild.lastElementChild.innerHTML;
        sum +=parseInt(sjv);
    }
    zj.innerHTML=sum;
}

